<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="记录工作中Vue项目遇到的问题及解决方案，持续更新"/>




  <meta name="keywords" content="vue相关问题" />










  <link rel="alternate" href="/teresa/atom.xml" title="Teresa">




  <link rel="shortcut icon" type="image/x-icon" href="/teresa/favicon.ico?v=2.9.0" />



<link rel="canonical" href="https://littlefaye.gitee.io/teresa/2018/08/15/about-vue/"/>



  <link rel="stylesheet" type="text/css" href="/teresa/lib/fancybox/jquery.fancybox.css" />




  <link rel="stylesheet" type="text/css" href="/teresa/lib/nprogress/nprogress.min.css" />



<link rel="stylesheet" type="text/css" href="/teresa/css/style.css?v=2.9.0" />



  
  <script id="baidu_analytics">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?9b4723f0455add81c1300727d6fe2f0f";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>





  <script src="//cdn1.lncld.net/static/js/3.1.1/av-min.js"></script>
  <script id="leancloud">
    AV.init({
      appId: "q8I1nPpo7445tVF84mvOlAyj-gzGzoHsz",
      appKey: "i9j12HoNltgi5uq4DLvonO0h"
    });
  </script>




<script>
  window.config = {"title":"Teresa","subtitle":null,"description":"about fe","author":"Teresa-哼哼","language":"zh-CN","timezone":null,"url":"https://littlefaye.gitee.io/teresa","root":"/teresa/","permalink":":year/:month/:day/:title/","permalink_defaults":null,"source_dir":"source","public_dir":"public","tag_dir":"tags","archive_dir":"archives","category_dir":"categories","code_dir":"downloads/code","i18n_dir":":lang","skip_render":null,"new_post_name":":title.md","default_layout":"post","titlecase":false,"external_link":true,"filename_case":0,"render_drafts":false,"post_asset_folder":false,"relative_link":false,"future":true,"highlight":{"enable":true,"auto_detect":false,"line_number":true,"tab_replace":null,"first_line_number":"always1"},"default_category":"uncategorized","category_map":null,"tag_map":null,"date_format":"YYYY-MM-DD","time_format":"HH:mm:ss","per_page":10,"pagination_dir":"page","theme":"even","deploy":{"type":"git","repo":"https://gitee.com/littleFaye/Teresa.git"},"ignore":[],"keywords":null,"index_generator":{"per_page":10,"order_by":"-date","path":""},"archive_generator":{"per_page":10,"yearly":true,"monthly":true,"daily":false},"tag_generator":{"per_page":10},"category_generator":{"per_page":10},"marked":{"gfm":true,"pedantic":false,"sanitize":false,"tables":true,"breaks":true,"smartLists":true,"smartypants":true,"modifyAnchors":"","autolink":true},"server":{"port":4000,"log":false,"ip":"0.0.0.0","compress":false,"header":true},"since":2015,"favicon":"/favicon.ico","rss":false,"menu":{"Home":"/","Archives":"/archives/","Tags":"/tags","Categories":"/categories","About":"/about"},"color":"Default","toc":true,"fancybox":true,"pjax":true,"copyright":{"enable":true,"license":"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\" target=\"_blank\">知识共享署名-非商业性使用 4.0 国际许可协议</a>"},"reward":{"enable":false,"qrCode":{"wechat":null,"alipay":null}},"social":{"email":"1748711164@qq.com","stack-overflow":null,"twitter":null,"facebook":null,"linkedin":null,"google":null,"github":"https://github.com/Faye0807","weibo":null,"zhihu":null,"douban":null,"pocket":null,"tumblr":null,"instagram":null},"leancloud":{"app_id":"q8I1nPpo7445tVF84mvOlAyj-gzGzoHsz","app_key":"i9j12HoNltgi5uq4DLvonO0h"},"baidu_analytics":"9b4723f0455add81c1300727d6fe2f0f","baidu_verification":null,"google_analytics":null,"google_verification":null,"disqus_shortname":null,"changyan":{"appid":null,"appkey":null},"livere_datauid":null,"version":"2.9.0"};
</script>

    <title> Vue相关问题记录 - Teresa </title>
  </head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/teresa/." class="logo">Teresa</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/teresa/">
        <li class="mobile-menu-item">
          
          
            首页
          
        </li>
      </a>
    
      <a href="/teresa/archives/">
        <li class="mobile-menu-item">
          
          
            归档
          
        </li>
      </a>
    
      <a href="/teresa/tags">
        <li class="mobile-menu-item">
          
          
            标签
          
        </li>
      </a>
    
      <a href="/teresa/categories">
        <li class="mobile-menu-item">
          
          
            分类
          
        </li>
      </a>
    
      <a href="/teresa/about">
        <li class="mobile-menu-item">
          
          
            关于
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/teresa/." class="logo">Teresa</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/teresa/">
            
            
              首页
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/teresa/archives/">
            
            
              归档
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/teresa/tags">
            
            
              标签
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/teresa/categories">
            
            
              分类
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/teresa/about">
            
            
              关于
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          Vue相关问题记录
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2018-08-15
        </span>
        
          <div class="post-category">
            
              <a href="/teresa/categories/Vue/">Vue</a>
            
          </div>
        
        
        <div class="post-visits"
             data-url="/teresa/2018/08/15/about-vue/"
             data-title="Vue相关问题记录">
            阅读次数 0
          </div>
        
      </div>
    </header>

    
    
  <div class="post-toc" id="post-toc">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Vues数据双向绑定实现"><span class="toc-text">Vues数据双向绑定实现</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#inupt输入框的change事件在失去焦点后触发"><span class="toc-text">inupt输入框的change事件在失去焦点后触发</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vue-input-file-多次上传不触发change事件问题"><span class="toc-text">vue input file 多次上传不触发change事件问题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Vue-父组件异步获取数据，子组件props获取不到"><span class="toc-text">Vue 父组件异步获取数据，子组件props获取不到</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#事件修饰符"><span class="toc-text">事件修饰符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#深度作用选择器-deep-or-gt-gt-gt"><span class="toc-text">深度作用选择器 /deep/ or &gt;&gt;&gt;</span></a></li></ol>
    </div>
  </div>



    <div class="post-content">
      
        <h2 id="Vues数据双向绑定实现"><a href="#Vues数据双向绑定实现" class="headerlink" title="Vues数据双向绑定实现"></a>Vues数据双向绑定实现</h2><p><a href="https://github.com/Faye0807/task/tree/master/fe/views/demo/vue%E5%8F%8C%E5%90%91%E7%BB%91%E5%AE%9A%E5%AE%9E%E7%8E%B0" target="_blank" rel="noopener">code</a></p>
<h2 id="inupt输入框的change事件在失去焦点后触发"><a href="#inupt输入框的change事件在失去焦点后触发" class="headerlink" title="inupt输入框的change事件在失去焦点后触发"></a>inupt输入框的<code>change</code>事件在失去焦点后触发</h2><p>此时跟blur事件很像，查阅后的方案是将处理程序添加到input事件上面 <a href="https://forum.vuejs.org/t/v-on-change/8670" target="_blank" rel="noopener">参考链接</a></p>
<h2 id="vue-input-file-多次上传不触发change事件问题"><a href="#vue-input-file-多次上传不触发change事件问题" class="headerlink" title="vue input file 多次上传不触发change事件问题"></a>vue input file 多次上传不触发change事件问题</h2><p>有以下几种方法（<a href="https://www.cnblogs.com/exhuasted/p/6185874.html" target="_blank" rel="noopener">参考链接</a>）：</p>
<ul>
<li>清空input的value值</li>
<li>替换掉原来的input 渲染一个新的input</li>
<li>将input放到一个表单里，change事件触发时将表单reset</li>
<li>替换原input，渲染新input并重新绑定change事件（这个方法对我有效）</li>
</ul>
<h2 id="Vue-父组件异步获取数据，子组件props获取不到"><a href="#Vue-父组件异步获取数据，子组件props获取不到" class="headerlink" title="Vue 父组件异步获取数据，子组件props获取不到"></a>Vue 父组件异步获取数据，子组件props获取不到</h2><p>由于我子组件需要拿到props后做数据处理，但发现无论是放到data，还是mounted，props里面值还是undefined；</p>
<p>查阅后了解到，异步请求数据有关；解决办法就是：引用子组件时，v-if先判断先props是否有值，如下<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;component-a v-<span class="keyword">if</span>=<span class="string">"dataList.length&gt;0"</span> :prop-a=<span class="string">"dataList"</span> /&gt;</span><br></pre></td></tr></table></figure></p>
<h2 id="事件修饰符"><a href="#事件修饰符" class="headerlink" title="事件修饰符"></a>事件修饰符</h2><p>事件修饰符不仅在绑定处理程序时候可以用，不绑定事件处理程序同样可用；比如阻止事件的传播<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;component-a @touch.stop /&gt;</span><br></pre></td></tr></table></figure></p>
<h2 id="深度作用选择器-deep-or-gt-gt-gt"><a href="#深度作用选择器-deep-or-gt-gt-gt" class="headerlink" title="深度作用选择器 /deep/ or &gt;&gt;&gt;"></a>深度作用选择器 <code>/deep/</code> or <code>&gt;&gt;&gt;</code></h2><p>当你的style标签添加<code>scoped</code> 使css有了作用域后，若想让自己的css可以更深的控制元素样式，则可以使用<code>/deep/</code> or <code>&gt;&gt;&gt;</code>; 比如你想在父组件更改子组件样式的时候，可能会需要这个选择器</p>
<p><a href="https://vue-loader-v14.vuejs.org/zh-cn/features/scoped-css.html" target="_blank" rel="noopener">参考链接</a></p>
<!-- ## 组件标签上添加class、style 与 元素上添加class、style的区别

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;component-a <span class="class"><span class="keyword">class</span></span>=<span class="string">"class-a"</span> style=<span class="string">"positon: absoult;color: #fff;"</span> /&gt;</span><br><span class="line">&lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"class-a"</span> style=<span class="string">"positon: absoult;color: #fff;"</span> /&gt;</span><br><span class="line"><span class="string">``</span><span class="string">` --&gt;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">## img 动态src属性值</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">`</span><span class="string">``</span>js</span><br><span class="line"><span class="comment">// 是加载不到图片的</span></span><br><span class="line">&lt;img :src=<span class="string">"flag ? './image/img.png' : './image.img2.png'"</span> /&gt;</span><br><span class="line"><span class="comment">// 需要这样</span></span><br><span class="line">&lt;img :src=<span class="string">"flag ? require('./image/img.png') : require('./image.img2.png')"</span> /&gt;</span><br><span class="line"><span class="comment">// 或者 将图片放到 static文件夹</span></span><br></pre></td></tr></table></figure>
<p><a href="https://blog.csdn.net/keji_123/article/details/79977210">vue 动态加载图片src的解决办法</a></p>
<h2 id="v-for"><a href="#v-for" class="headerlink" title="v-for"></a>v-for</h2><blockquote>
<p>注意 :key 的值若不唯一会报错</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[Vue warn]: Duplicate keys detected: <span class="string">'&#123;key&#125;'</span>. This may cause an update error.  found <span class="keyword">in</span>  ---&gt; &lt;Anonymous&gt;        &lt;Nuxt&gt;          &lt;Default&gt; at layouts/default.vue            &lt;Root&gt;</span><br></pre></td></tr></table></figure>
<h2 id="引用文件"><a href="#引用文件" class="headerlink" title="引用文件"></a>引用文件</h2><p>若引用路径文件名字母大小与文件命名不一致，或多处引用路径大小不一致，vue会有警告⚠️</p>
-->
      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>原文作者: </span>
      <a href="https://littlefaye.gitee.io/teresa">Teresa-哼哼</a>
    </p>
    <p class="copyright-item">
      <span>原文链接: </span>
      <a href="https://littlefaye.gitee.io/teresa/2018/08/15/about-vue/">https://littlefaye.gitee.io/teresa/2018/08/15/about-vue/</a>
    </p>
    <p class="copyright-item">
      <span>许可协议: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/teresa/tags/Vue/">Vue</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
      <a class="prev" href="/teresa/2018/08/20/css居中/">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default">css居中</span>
        <span class="prev-text nav-mobile">上一篇</span>
      </a>
    
    
      <a class="next" href="/teresa/2018/08/14/vue-cli/">
        <span class="next-text nav-default">vue-cli项目部署到gitee Pages</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:1748711164@qq.com" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
        
          <a href="https://github.com/Faye0807" class="iconfont icon-github" title="github"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
    
    
  </div>


<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://hexo.io/">Hexo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even">Even</a>
  </span>

  <span class="copyright-year">
    
    &copy; 
     
      2015 - 
    
    2018

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">Teresa-哼哼</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  

  



    
  



  
  





  
    <script type="text/javascript" src="/teresa/lib/jquery/jquery.min.js"></script>
  

  
    <script type="text/javascript" src="/teresa/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/teresa/lib/fancybox/jquery.fancybox.pack.js"></script>
  

  
    <script type="text/javascript" src="/teresa/lib/pjax/jquery.pjax.min.js"></script>
  

  
    <script type="text/javascript" src="/teresa/lib/nprogress/nprogress.min.js"></script>
  


    <script type="text/javascript" src="/teresa/js/src/even.js?v=2.9.0"></script>

  </body>
</html>
